<template v-if="update">
  <view>
    <uni-evaluate :list-data="listData" :rate="rate"></uni-evaluate>
    <uni-load-more v-if="listData&&listData.length>10" :status="status" />
  </view>
</template>

<script>
import UniEvaluate from "../../../../components/xiujun-evaluate/uni-evaluate";
import {EvaluationService} from "../../../../api/buyer/public/evaluate";
import {attachmentService} from "../../../../api/buyer/public/attachmentService";
import {BASE_IMG_URL} from "../../../../api/service";

export default {
  name: "index",
  components: {UniEvaluate},
  data(){
    return{
      status:"more",
      rate:4,
      listData:[
        // {
        //   userAvatar:"https://img01.yzcdn.cn/vant/cat.jpeg",
        //   userName:"测试1",
        //   score:"5",
        //   createDatetime:"2022-02-22",
        //   content:"真的好极了",
        //   imgs:["https://cdn.uviewui.com/uview/album/1.jpg","https://cdn.uviewui.com/uview/album/1.jpg","https://cdn.uviewui.com/uview/album/1.jpg"
        //     ,"https://cdn.uviewui.com/uview/album/1.jpg","https://cdn.uviewui.com/uview/album/1.jpg","https://cdn.uviewui.com/uview/album/1.jpg"]
        // },
      ],
      queryParams:{
        currentPage:1,
        pageSize:30,
        filters:{

        }
      },
      update:true,
    }
  },
  async onReachBottom() {
    // console.log("onReachBottom");
    if(this.status!="no-more"){
      this.queryParams.currentPage+=1;
      this.status="loading";
      this.init("loadMore")
    }
  },
  watch: {
    listData: {
      handler(val) {
        this.$nextTick(() => {
          this.reload();
        });
      },
      immediate: true,
      deep: true
    }
  },
  onLoad(option) {
    const s = decodeURIComponent(option.commodityId);
    this.queryParams.filters.commodityId= JSON.parse(s);
    console.log(this.queryParams)
    this.init("load")
  },
  methods:{
    init(type){
      EvaluationService.findEvaluations(this.queryParams).then((res)=>{
        if(type=="load"){
          this.listData=[];
        }
        console.log(res)
        let start=this.listData.length;
        this.listData=this.listData.concat(res.data.datas);
        let end=this.listData.length;
        this.loadImage(start,end);
        if(res.data.datas&&res.data.datas.length<this.queryParams.pageSize){
          this.status="no-more"
        }else{
          this.status="more"
        }

        // console.log(this.listData)
      }).catch((err)=>{
        console.log(err)
      });
    },
    loadImage(start,end){
      for (let i = start; i < end; i++) {
        attachmentService.findFile(this.listData[i].eid,"evaluation").then((res)=>{
          console.log(res.data)
          let images=[];
          res.data.forEach(item=>{
            images.push(BASE_IMG_URL+item.attachmentAddr)
          })
          this.listData[i].imgs=images;
          console.log("..",this.listData)
          // this.reload()
        })
      }

    },
    reload(){
      this.update=false
      this.update=true
    }
  }
}
</script>

<style scoped>

</style>